<script type='text/javascript' src="<?php echo $this->basePath('public/css/dbblack/js/artdialog/artDialog.js?skin=simple'); ?>"></script>
<script type='text/javascript' src="<?php echo $this->basePath('public/css/dbblack/js/artdialog/plugins/iframeTools.js'); ?>"></script>

<div class="mt20 container">
    <?php
    $cart_info_top_banner = $this->frontwebsite()->getShopAd('cart', 'info_top_banner');
    if($cart_info_top_banner != '') {
        echo $cart_info_top_banner;
    }
    ?>

    <?php if ($this->cart_array) { ?>
    <table width="100%" class="simple">
        <tr>
            <th style="width:60px;"><?php echo $this->translate('商品'); ?></th>
            <th style="width:200px;"><?php echo $this->translate('名称'); ?></th>
            <th style="width:100px;"><?php echo $this->translate('货号'); ?></th>
            <th style="width:160px;"><?php echo $this->translate('规格'); ?></th>
            <th style="width:100px;"><?php echo $this->translate('单价'); ?></th>
            <th style="width:120px;"><?php echo $this->translate('数量'); ?></th>
            <th style="width:80px;"><?php echo $this->translate('小计'); ?></th>
            <th style="width:40px;"><?php echo $this->translate('操作'); ?></th>
        </tr>
        <?php $i=1; foreach ($this->cart_array as $cart_key => $goods_value) { ?>
        <tr class="<?php echo $i%2==1 ? 'old' : 'even'; ?>" id="<?php echo $cart_key; ?>">
            <td><a href="<?php echo $this->url('frontgoods/default', array('goods_id'=>$goods_value['goods_id'], 'class_id'=>$goods_value['class_id'])); ?>" target="_blank"><img src="<?php echo $this->basePath($this->frontwebsite()->shopGoodsImage($goods_value['goods_image'])); ?>" width="50" height="50"></a></td>
            <td><a href="<?php echo $this->url('frontgoods/default', array('goods_id'=>$goods_value['goods_id'], 'class_id'=>$goods_value['class_id'])); ?>" target="_blank"><?php echo $this->escapeHtml($goods_value['goods_name']);?></a></td>
            <td><?php echo $this->escapeHtml($goods_value['goods_item']);?></td>
            <td>
                <?php
                if($goods_value['goods_color_name'] == '' and $goods_value['goods_size_name'] == '' and $goods_value['goods_adv_tag_name'] == '') {
                    echo $this->translate('无');
                } else {
                    if(!empty($goods_value['goods_adv_tag_name'])) {
                        echo $goods_value['goods_adv_tag_name'];
                    } else {
                        if($goods_value['goods_color_name'] != '') echo '<p>' . $goods_value['goods_color_name'] . '</p>';
                        if($goods_value['goods_size_name'] != '') echo '<p>' . $goods_value['goods_size_name'] . '</p>';
                    }
                }
                ?>
            </td>
            <td>
                <?php echo $this->frontwebsite()->shopPriceExtend($goods_value['goods_shop_price']); ?>
                <?php if(isset($goods_value['integral_num']) and $goods_value['integral_num'] > 0) { ?>
                    (<?php echo $this->translate('或').$goods_value['integral_num'].$this->translate('积分'); ?>)
                <?php } ?>
            </td>
            <td>
                <select style="height: 25px;width: 80px;" id="<?php echo $cart_key; ?>buy_num" name="<?php echo $cart_key; ?>buy_num" onchange="edit_cart_goods_buy_num('<?php echo $cart_key; ?>','<?php echo $cart_key; ?>buy_num');">
                    <?php
                    $cart_buy_min_num = ($goods_value['buy_min_num'] > 0 ? $goods_value['buy_min_num'] : 1);
                    if($goods_value['goods_stock_state'] == 1) {//当有货开启时，不对库存进行刻意判断
                        $buy_max_num = ($goods_value['buy_num'] > 50 ? $goods_value['buy_num'] : 50);
                    } else {
                        $buy_max_num = ($goods_value['goods_stock']>50 ? ($goods_value['buy_num'] <= 50 ? 50 : $goods_value['buy_num']) : $goods_value['goods_stock']);
                    }
                    $cart_buy_max_num = ($goods_value['buy_max_num'] > 0 ? $goods_value['buy_max_num'] : $buy_max_num);

                    for ($i = $cart_buy_min_num; $i <= $cart_buy_max_num; $i++) { ?>
                        <option value="<?php echo $i; ?>" <?php if ($i == $goods_value['buy_num']) echo 'selected="selected"'; ?>><?php echo $i; ?></option>
                    <?php } ?>
                </select>
                <?php if($goods_value['goods_weight'] > 0) echo '<p>('.$this->translate('单品重:').'<strong>'.$goods_value['goods_weight'].'</strong>'.$this->translate('千克').')</p>'; ?>
            </td>
            <td class="amount red">
                <?php echo $this->frontwebsite()->shopPriceSymbol().$this->frontwebsite()->shopPrice($goods_value['goods_shop_price'])*$goods_value['buy_num'].$this->frontwebsite()->shopPriceUnit(); ?>
                <?php if(isset($goods_value['integral_num']) and $goods_value['integral_num'] > 0) { ?>
                    (<?php echo $this->translate('或').$goods_value['integral_num']*$goods_value['buy_num'].$this->translate('积分'); ?>)
                <?php } ?>
            </td>
            <td class="tc"><a href="#" class="icon-close-16"></a></td>
        </tr>
        <?php $i++; } ?>
    </table>
    <div class="mb10 clearfix" style="padding:10px; background: #f0f0f0;">
        <span class="fr">
            <?php $total_weight = $this->frontwebsite()->getCartTotalWeight(); if ($total_weight > 0) { ?>
                <?php echo $this->translate('商品总重').'：<span style="font-size: 24px;font-family: tahoma"><b class="red" >'.$total_weight; ?><?php echo $this->translate('千克'); ?></b></span>&nbsp;&nbsp;&nbsp;
            <?php } ?>
            <?php if($this->promotionsCost['discountCost'] and $this->promotionsCost['discountCost'] > 0) { ?>
                <?php echo $this->translate('优惠金额'); if(!empty($this->promotionsCost['discountName'])) echo '(<font color="#139EE6">' . $this->promotionsCost['discountName'] . '</font>)'; ?>：<span style="font-size: 24px;font-family: tahoma">-<?php echo $this->frontwebsite()->shopPriceSymbol().'<b class="red" >'.$this->frontwebsite()->shopPrice($this->promotionsCost['discountCost']).$this->frontwebsite()->shopPriceUnit(); ?></b></span>&nbsp;&nbsp;&nbsp;
            <?php } ?>
            <?php if($this->integralInfo['integralNum'] and $this->integralInfo['integralNum'] > 0) { ?>
                <?php echo $this->translate('获得消费积分'); if(!empty($this->integralInfo['integalRuleInfo'])) echo '(<font color="#139EE6">' . $this->integralInfo['integalRuleInfo'] . '</font>)'; ?>：<span style="font-size: 24px;font-family: tahoma"><b class="red" ><?php echo $this->integralInfo['integralNum']; echo $this->translate('积分'); ?></b></span>&nbsp;&nbsp;&nbsp;
            <?php } ?>
            <?php if($this->integralInfo1['integralNum'] and $this->integralInfo1['integralNum'] > 0) { ?>
                <?php echo $this->translate('获得等级积分'); if(!empty($this->integralInfo1['integalRuleInfo'])) echo '(<font color="#139EE6">' . $this->integralInfo1['integalRuleInfo'] . '</font>)'; ?>：<span style="font-size: 24px;font-family: tahoma"><b class="red" ><?php echo $this->integralInfo1['integralNum']; echo $this->translate('积分'); ?></b></span>&nbsp;&nbsp;&nbsp;
            <?php } ?>
            <?php echo $this->translate('商品总价(不含运费)'); ?>：<span style="font-size: 24px;font-family: tahoma"><span class="currency-symbol"><?php echo $this->frontwebsite()->shopPriceSymbol(); ?></span><b class="cart-total red" ><?php echo $this->frontwebsite()->getCartTotal().$this->frontwebsite()->shopPriceUnit(); ?></b></span>
        </span>
    </div>

    <div class="mt10 clearfix">
        <p class="fr"><a class="btn btn-gray" href="<?php echo $this->url('shopfront/default'); ?>"><?php echo $this->translate('继续购物'); ?></a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-main" href="<?php echo $this->url('frontcart/default', array('action'=>'setaddress')); ?>"><?php echo $this->translate('立即结算'); ?></a></p></div>
</div>
<?php } else { ?>
<div class="mt20 mb20 p20 box">
    <p class="cart-empty ie6png"><?php echo $this->translate('购物车内暂时没有商品'); ?>，<a  href="<?php echo $this->url('shopfront/default'); ?>"><?php echo $this->translate('去首页'); ?></a> <?php echo $this->translate('挑选喜欢的商品'); ?>。</p>

</div>
<div class="mt10 clearfix">
    <p class="fr"><a class="btn btn-main" href="<?php echo $this->url('shopfront/default'); ?>"> < <?php echo $this->translate('继续购物'); ?></a></p>
</div>
<?php } ?>
<script type="text/javascript">
    $(".icon-close-16").on("click",function(){
        if(window.confirm('<?php echo $this->translate('您确实要将购物车中的该商品删除吗？'); ?>')) {
            $.post("<?php echo $this->url('frontcart/default',array('action'=>'delCartGoods')); ?>",{cart_key:$(this).parent().parent().attr("id")},
                function(data){
                    if(data == 'true') {
                        window.location.href="<?php echo $this->url('frontcart/default'); ?>";
                    }
                });
        }
    })
    //编辑购物车
    function edit_cart_goods_buy_num (cart_key, buy_num_id) {
        var edit_buy_num = $('#'+buy_num_id).val();
        $.post("<?php echo $this->url('frontcart/default',array('action'=>'editCartGoods')); ?>",{cart_key:cart_key,type:'buy_num',buy_num:edit_buy_num},
            function(data){
                if(data != 'true') {
                    art.dialog.tips(data);
                }
                window.location.href="<?php echo $this->url('frontcart/default'); ?>";
            });
    }
</script>
